<?php

include_once 'Classes/PHPCodeProvider.php';

/*
 * Create an instance of the CodeGeneratorOptions class
 * using the default options for code generation.
 */

$options = new CodeGeneratorOptions();

/*
 * Create an instance of the IndentedTextWriter.
 * After the generateCodeFromStatement call
 * $writer will hold the generated code.
 */

$writer = new IndentedTextWriter();

/*
 * The PHPCodeProvider instance
 */

$provider = new PHPCodeProvider();

/*
 * a variable assignment statement
 */

$assignStatement1 = new AssignStatement(
    new VariableReferenceExpression('won'), 
    new PrimitiveExpression(0));

/*
 * Generate the code.
 */

$provider->generateCodeFromStatement($assignStatement1, $writer, $options);

/*
 * Assign value to an object property
 */

$assignStatement2 = new AssignStatement(
    new FieldReferenceExpression('gameFinished', new ThisReferenceExpression()),
    new PrimitiveExpression(false));

/*
 * Generate the code.
 */

$provider->generateCodeFromStatement($assignStatement2, $writer, $options);

/*
 * String concatenation compound assignment operator
 */

$assignStatement3 = new AssignStatement(
    new VariableReferenceExpression('a'), 
    new PrimitiveExpression('World'), 
    CompoundAssignmentOperator::CONCATENATE_ASSIGN);

/*
 * Generate the code.
 */

$provider->generateCodeFromStatement($assignStatement3, $writer, $options);

/*
 * Addition compound operator
 */

$assignStatement4 = new AssignStatement(
    new VariableReferenceExpression('a'), 
    new PrimitiveExpression(5), 
    CompoundAssignmentOperator::PLUS_ASSIGN);

$provider->generateCodeFromStatement($assignStatement4, $writer, $options);

echo 
    '<pre>' . str_replace(
        '<br />', '', highlight_string($writer->get_String(), true)) . 
    '<pre/>';

/*
 * The output should be:
 * 
 * $won = 0;
 * $this->gameFinished = false;
 * $a .= 'World';
 * $a += 5;
 */

?>
